package com.shensi.adminCollect.controller.customer;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.common.utils.poi.ExcelUtil;
import com.shensi.adminCollect.domain.customer.CustomerDialogueAdTemplate;
import com.shensi.adminCollect.service.customer.ICustomerDialogueAdTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * adController
 * 
 * @author joeley
 * @date 2022-09-29
 */
@RestController
@RequestMapping("/customer/dialogue")
public class CustomerDialogueAdTemplateController extends BaseController
{
    @Autowired
    private ICustomerDialogueAdTemplateService customerDialogueAdTemplateService;

    /**
     * 查询ad列表
     */
    @PreAuthorize("@ss.hasPermi('customer:dialogue:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerDialogueAdTemplate customerDialogueAdTemplate)
    {
        startPage();
        List<CustomerDialogueAdTemplate> list = customerDialogueAdTemplateService.selectCustomerDialogueAdTemplateList(customerDialogueAdTemplate);
        return getDataTable(list);
    }

    /**
     * 导出ad列表
     */
    @PreAuthorize("@ss.hasPermi('customer:dialogue:export')")
    @GetMapping("/export")
    public AjaxResult export(CustomerDialogueAdTemplate customerDialogueAdTemplate)
    {
        List<CustomerDialogueAdTemplate> list = customerDialogueAdTemplateService.selectCustomerDialogueAdTemplateList(customerDialogueAdTemplate);
        ExcelUtil<CustomerDialogueAdTemplate> util = new ExcelUtil<CustomerDialogueAdTemplate>(CustomerDialogueAdTemplate.class);
        return util.exportExcel(list, "dialogue");
    }

    /**
     * 获取ad详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:dialogue:query')")
    @GetMapping(value = "/{adId}")
    public AjaxResult getInfo(@PathVariable("adId") Long adId)
    {
        return AjaxResult.success(customerDialogueAdTemplateService.selectCustomerDialogueAdTemplateById(adId));
    }

    /**
     * 新增ad
     */
    @PreAuthorize("@ss.hasPermi('customer:dialogue:add')")
    @PostMapping
    public AjaxResult add(@RequestBody CustomerDialogueAdTemplate customerDialogueAdTemplate)
    {
        return toAjax(customerDialogueAdTemplateService.insertCustomerDialogueAdTemplate(customerDialogueAdTemplate));
    }

    /**
     * 修改ad
     */
    @PreAuthorize("@ss.hasPermi('customer:dialogue:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerDialogueAdTemplate customerDialogueAdTemplate)
    {
        return toAjax(customerDialogueAdTemplateService.updateCustomerDialogueAdTemplate(customerDialogueAdTemplate));
    }

    /**
     * 删除ad
     */
    @PreAuthorize("@ss.hasPermi('customer:dialogue:remove')")
    @DeleteMapping("/{adIds}")
    public AjaxResult remove(@PathVariable Long[] adIds)
    {
        return toAjax(customerDialogueAdTemplateService.deleteCustomerDialogueAdTemplateByIds(adIds));
    }
}
